﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package Transactions {
    import Engine.Transactions.*;
    import Display.DialogUI.*;
    import Classes.*;
    import Display.*;

    public class TBuyMysteryCrate extends Transaction {

        private var m_itemName:String;
        private var m_itemAmount:int;
        private var m_success:Boolean;
        private var m_unlockItemName:String;

        public function TBuyMysteryCrate(_arg1:Item, _arg2:int, _arg3:String=null){
            this.m_itemName = _arg1.name;
            this.m_itemAmount = _arg2;
            this.m_unlockItemName = _arg3;
            if (Global.player.inventory.spareCapacity <= 0){
                UI.displayMessage(ZLoc.t("Dialogs", "InventoryFull"));
            } else {
                if ((Global.player.cash - _arg1.cash) > -1){
                    Global.player.cash = (Global.player.cash - (_arg1.cash * this.m_itemAmount));
                    this.m_success = true;
                };
            };
        }
        override public function perform():void{
            if (this.m_success){
                signedCall("UserService.buyConsumable", this.m_itemName, this.m_itemAmount, this.m_unlockItemName);
            };
        }
        override protected function onAmfComplete(_arg1:Object):void{
            var _local2:Dialog;
            var _local3:Item;
            var _local4:Item;
            var _local5:String;
            var _local6:String;
            var _local7:MysteryCrateDialog;
            super.onAmfComplete(_arg1);
            if (((((_arg1) && (_arg1.data))) && (_arg1.data.itemName))){
                this.m_itemName = _arg1.data.itemName;
                Global.player.inventory.addItems(this.m_itemName, this.m_itemAmount);
                _local2 = UI.currentPopup;
                _local3 = Global.gameSettings.getItemByName(this.m_itemName);
                if (((_local2) && ((_local2 is MysteryCrateDialog)))){
                    MysteryCrateDialog(UI.currentPopup).showWinnings(_local3);
                } else {
                    _local4 = Global.gameSettings.getItemByName(_local3.name);
                    _local5 = ZLoc.t("Items", (_local3.name + "_friendlyName"));
                    _local6 = ZLoc.t("Dialogs", "Mystery_Crate_anticipation", {item:_local5});
                    _local7 = new MysteryCrateDialog(_local6, "mysteryCrateDialog", GenericDialogView.TYPE_CUSTOM_OK, null, "Mystery_Crate", _local4.iconRelative, true, GenericDialogView.ICON_POS_LEFT, "", null, ZLoc.t("Dialogs", "Mystery_Crate_ok"));
                    UI.displayPopup(_local7, true);
                    _local7.showWinnings(_local3);
                };
            };
        }

    }
}//package Transactions 
